{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import glob\n",
    "import pandas as pd\n",
    "import xml.etree.ElementTree as ET"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#def label2det(label):\n",
    "#    f = open('val.txt', 'a+')\n",
    "#    f.write('/media/erress/Personal/Programming/BennettUniversity/bdd100k/images/100k/val/%s.jpg' % (label['name']))\n",
    "#    f.write('\\n')\n",
    "#    f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def change_dir(path):\n",
    "    xml_list = []\n",
    "    f = open('testlist.txt', 'a+')\n",
    "    for xml_file in glob.glob(path + '/*.xml'):\n",
    "        tree = ET.parse(xml_file)\n",
    "        root = tree.getroot()\n",
    "        #for member in root.findall('object'):\n",
    "           # print(member.find('bndbox')[0].text)            \n",
    "        value = root.find('filename').text\n",
    "        f.write('train_data/images/%s' % (value))\n",
    "        f.write('\\n')\n",
    "    f.close() \n",
    "    print('file created')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def main():\n",
    "    image_path = \"F:/intern/RoadDamageDataset/Sumida/ann\"#os.path.join(os.getcwd(), 'annotations')\n",
    "    xml_df = change_dir(image_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file created\n"
     ]
    }
   ],
   "source": [
    "main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
